*
*	Run SP-DA
*


gen priority_score_inv = -priority_score
forvalues proposal_round = 1/40 {
	sort applicant_id rank
	bys applicant_id: gen rank_temp = _n
	gen proposer = rank_temp == 1
	sort contract_id proposer priority_score_inv applicant_id
	bys contract_id proposer: gen contract_rank = _n
	gen rejected_temp = 1 if proposer == 1 & contract_rank > capacity
	drop if rejected_temp == 1
	drop rank_temp proposer contract_rank rejected_temp
}

sort applicant_id rank
bys applicant_id: gen rank_temp = _n
gen proposer = rank_temp == 1

keep if proposer == 1
drop proposer

gen contract_id_spda = contract_id
gen rank_spda = rank
gen state_funded_spda = state_funded
gen program_id_spda = program_id
gen priority_score_spda = priority_score
gen capacity_spda = capacity
keep id applicant_id contract_id_spda rank_spda state_funded_spda ///
	program_id_spda priority_score_spda capacity_spda
lab var contract_id_spda "Contract id (SP-DA)"
lab var rank_spda "Rank (SP-DA)"
lab var state_funded_spda "State-funded (SP-DA)"
lab var program_id_spda "Program_id (SPDA)"
lab var priority_score_spda "Priority score (SPDA)"
lab var capacity_spda "Capacity (SPDA)"
